﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;

namespace designmodule.behavioralmodule.Interpreter.Demo
{
    public abstract class Expression
    {
        public void Interpret(Playcontext context)
        {
            if (context.Text.Length == 0)
            {
                return;
            }
            else
            {
                string playkey = context.Text.Substring(0,1);
                context.Text = context.Text.Substring(2);
                double value =
                    Convert.ToDouble(
                        context.Text.Substring(0, context.Text.IndexOf(" ")));

                context.Text =
                    context.Text.Substring(context.Text.IndexOf(" ") + 1);

                Execute(playkey,value);
            }


        }

        public abstract void Execute(string key,double value);

    }

    public class Note:Expression
    {
        public override void Execute(string key, double value)
        {
            string note = "";
            switch (key)
            {
                case "C":
                    note = "1";
                    break;
                case "D":
                    note = "2";
                    break;
                case "E":
                    note = "3";
                    break;
                case "F":
                    note = "4";
                    break;
            }
        }
    }


    public class Scale: Expression
    {
        public override void Execute(string key, double value)
        {
            string scale = "";
            switch (value)
            {
                case 1:
                    scale = "低音";
                    break;
                case 2:
                    scale = "高音";
                    break;
            }
        }
    }
}
